package com.ruoyi.decision.service.impl;

import java.util.List;
import java.util.Locale;
import java.util.UUID;

import com.ruoyi.decision.domain.UserTaskStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.decision.mapper.UserSchemeStrategyMapper;
import com.ruoyi.decision.domain.UserSchemeStrategy;
import com.ruoyi.decision.service.IUserSchemeStrategyService;

/**
 * 用户，方案，策略中间Service业务层处理
 * 
 * @author zbw
 * @date 2022-08-19
 */
@Service
public class UserSchemeStrategyServiceImpl implements IUserSchemeStrategyService 
{
    @Autowired
    private UserSchemeStrategyMapper userSchemeStrategyMapper;

    /**
     * 查询用户，方案，策略中间
     * 
     * @param id 用户，方案，策略中间主键
     * @return 用户，方案，策略中间
     */
    @Override
    public UserSchemeStrategy selectUserSchemeStrategyById(String id)
    {
        return userSchemeStrategyMapper.selectUserSchemeStrategyById(id);
    }

    /**
     * 查询用户，方案，策略中间列表
     * 
     * @param userSchemeStrategy 用户，方案，策略中间
     * @return 用户，方案，策略中间
     */
    @Override
    public List<UserSchemeStrategy> selectUserSchemeStrategyList(UserSchemeStrategy userSchemeStrategy)
    {
        return userSchemeStrategyMapper.selectUserSchemeStrategyList(userSchemeStrategy);
    }

    /**
     * 新增用户，方案，策略中间
     * 
     * @param userSchemeStrategy 用户，方案，策略中间
     * @return 结果
     */
    @Override
    public int insertUserSchemeStrategy(UserSchemeStrategy userSchemeStrategy)
    {
        UserSchemeStrategy userSchemeStrategy1 = new UserSchemeStrategy();
        try {
            for (String strategyID : userSchemeStrategy.getStrategyIds()) {
                String id = UUID.randomUUID().toString().toLowerCase(Locale.ROOT).replace("-","");
                userSchemeStrategy1.setId(id);
                userSchemeStrategy1.setUserId(userSchemeStrategy.getUserId());
                userSchemeStrategy1.setSchemeId(userSchemeStrategy.getSchemeId());
                userSchemeStrategy1.setStrategyId(strategyID);
                userSchemeStrategyMapper.insertUserSchemeStrategy(userSchemeStrategy1);
            }
            return 1;
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }

    /**
     * 修改用户，方案，策略中间
     * 
     * @param userSchemeStrategy 用户，方案，策略中间
     * @return 结果
     */
    @Override
    public int updateUserSchemeStrategy(UserSchemeStrategy userSchemeStrategy)
    {
        return userSchemeStrategyMapper.updateUserSchemeStrategy(userSchemeStrategy);
    }

    /**
     * 批量删除用户，方案，策略中间
     * 
     * @param ids 需要删除的用户，方案，策略中间主键
     * @return 结果
     */
    @Override
    public int deleteUserSchemeStrategyByIds(String[] ids)
    {
        return userSchemeStrategyMapper.deleteUserSchemeStrategyByIds(ids);
    }

    /**
     * 删除用户，方案，策略中间信息
     * 
     * @param id 用户，方案，策略中间主键
     * @return 结果
     */
    @Override
    public int deleteUserSchemeStrategyById(String id)
    {
        return userSchemeStrategyMapper.deleteUserSchemeStrategyById(id);
    }
}
